package com.xingda.packing.domain;

import com.xingda.packing.enums.WheelType;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 缓存位
 */
@Data
public class CacheLocation implements Serializable {

    private static final long serialVersionUID = 5631618686580684486L;

    /**
     * 位置编号
     */
    private int no;

    /**
     * 放入时间
     */
    private LocalDateTime putTime;

    /**
     * 工字轮
     */
    private Wheel wheel;

    /**
     * 是否启用
     */
    private Integer enable;

    /**
     * 当前位置是否被占用
     */
    public boolean isOccupy() {
        return Objects.nonNull(wheel);
    }

    /**
     * 启用
     */
    public boolean isEnable() {
        return Objects.isNull(enable) || enable == 1;
    }

    /**
     * 当前位置是否为空
     */
    public boolean isEmpty() {
        return Objects.isNull(wheel);
    }

    public boolean canPut() {
        return isEnable() && isEmpty();
    }

    public void clear() {
        this.wheel = null;
        this.putTime = null;
    }

    public int getProductType() {
        return Objects.isNull(wheel) ? 0 : WheelType.getByTypeName(wheel.getVFree2()).getTypeId();
    }
}
